/*

METOO and MOIAUSSI! (C) Copyright Bill Buckels 1990 - 2008.
All rights reserved.
Apple //e ProDOS 8 Version 2.0

Written in Manx Aztec C65 Version 3.2b
MS-DOS cross-development environment

*/

/* word spin */

#include "me2.h"

/* I have made this predictable
   to make the game a little easier

   A random skip factor that
   excludes 3. 9, and 1 would
   make this less predictable
   but why bother?

   The kid still needs to match the
   picture with the word which is
   really the object here, not to
   play roulette.

*/
#define SPINS 27
int spinpos[27][3] = {
	0, 0, 0,
	0, 0, 1,
	0, 0, 2,
	0, 1, 0,
	0, 1, 1,
	0, 1, 2,
	0, 2, 0,
	0, 2, 1,
	0, 2, 2,
	1, 0, 0,
	1, 0, 1,
	1, 0, 2,
	1, 1, 0,
	1, 1, 1,
    1, 1, 2,
	1, 2, 0,
	1, 2, 1,
	1, 2, 2,
	2, 0, 0,
    2, 0, 1,
	2, 0, 2,
    2, 1, 0,
	2, 1, 1,
	2, 1, 2,
	2, 2, 0,
	2, 2, 1,
	2, 2, 2};

int spinanswer[3] = { 0,13,26};

ovmain(answers)
int answers;
{
  int idx, jdx, spinstart;
  int c, mychoice, myanswer;

  /* override for modules 3 and 4 */
  /* only one round of play */
  /* only 3 minipix */
  answers = 10;
  multiples = 3;

  layout(3);

  /* mouse position is not used
     in the word spin module */
  for (;;) {

      mychoice = randomchoice();
      myanswer = spinanswer[mychoice];
      spinstart = randomseed[6]%SPINS;

      for (idx = 0; idx < multiples; idx++) {
		 loadmini(randomseed[idx], idx);
		 picpos[idx][2] = randomseed[idx];
	     showmini(idx, P_BLACK, 0);
	  }
      showtext(picpos[mychoice][2],0);
      kbclear();
      for (;;) {

          for (idx = 0; idx < multiples; idx++) {
		      jdx = spinpos[spinstart][idx];
		      showmini(idx, PUT, jdx);
		  }
          if(soundflag)happy();
          c = waitkey(10); /* see if a key is waiting */
          if (c!=0) {
			  kbclear();
			  /* break on ESCAPE, SPACE, or ENTER */
			  if (c == 27 || c == 32 || c == 13)break;

		  }
		  spinstart++;
		  if (spinstart == SPINS)spinstart = 0;

	  }
      /* quit on ESCAPE */
	  if (c == 27)break;

	  if (spinstart == myanswer) {
        shownumber(answers);
        answers++;
        if (answers==20) return answers;
	  }
	  else {
		  if(soundflag)bronx();
	  }
	  showtext(0,1); /* erase old text */

  }

  return 0;
}

